import Vue from 'vue'
import 'normalize.css';
import Router from 'vue-router';
import App from './App'; // 局部组件
import element from 'element-ui';
import '../node_modules/element-ui/lib/theme-chalk/index.css';
import login from './components/login';
import reg from './components/reg';
import details from './components/details'
import details_s from './components/aa';

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'App',
      component: App,
      children: [{
        path: 'login',
        name: 'login',
        component: login,
      },
        {
          path: 'reg',
          name: 'reg',
          component: reg,
        }]
    },
    {
      path: '/details',
      name: 'details',
      component: details,
      meta: {
        requireLogin: true,
      },
      children: [{
        path: 'details_a',
        name: 'details_a',
        component: aa
      }]
    }
  ]
});
const auth = false;
router.beforeEach((to, from, next) => {
  if (to.matched.some((value => value.meta.requireLogin))) {
    if (auth) {
      next();
    } else {
      next('/login')
    }
  } else {
    next();
  }
});
Vue.config.productionTip = false;
Vue.use(element);
Vue.use(Router);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
});
